<template>
  <div>
    <form action="/">
      <van-search
        v-model="value"
        show-action
        placeholder="请输入搜索关键词"
        @search="onSearch"
        @cancel="onCancel"
      />
    </form>
    <div v-for="v in mlist" :key="v.id" class="item" @click="play(v)">
      <div class="item_div1">
        <img :src="v.albumPicUrl" />
      </div>
      <div class="item_div2">
        <p>歌名：{{ v.musicName }}</p>
        <p>专辑：{{ v.albumName }}</p>
        <p>歌手：{{ v.artistName }}</p>
        <p>类型：{{ v.navigationName }}</p>
      </div>
    </div>
    <van-empty description="未找到搜索的歌曲" v-show="isShow" />
  </div>
</template>

<script>
import url from "../tools/url";
export default {
  name: "Search",
  data() {
    return {
      value: "",
      mlist: [],
      isShow: false,
    };
  },
  methods: {
    onCancel() {
      this.$router.go(-1);
    },
    onSearch() {
      var token = sessionStorage.getItem("token");
      var str = `token=${token}&keyword=${this.value}`;
      this.axios.post(url.GET_FIND_BY_KEYWORD, str).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          if (res.data.data.length == 0) {
            this.isShow = true;
          } else {
            this.mlist = res.data.data;
          }
        } else {
          this.$router.push("/login");
        }
      });
    },
    play(v) {
      this.$store.commit("savem", v);
    },
  },
  computed: {},
};
</script>
<style scoped>
* {
  margin: 0;
  padding: 0;
}
.van-search {
  padding: 5px 40px;
}
.van-search__action {
  margin-left: 15px;
}
.item {
  display: flex;
  background: white;
  margin-top: 10px;
  padding: 10px;
}
.item .item_div1 {
  width: 20%;
}
.item .item_div1 img {
  width: 100%;
  border-radius: 50%;
}
.item .item_div2 {
  margin-left: 10px;
}
.item div {
  width: 75%;
  font-size: 10px;
}
</style>
